<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="../public/css/node.css">
  <link rel="stylesheet" href="../public/css/bootstrap.min.css">
  <link rel="stylesheet" href="../public/js/theme/default/layer.css">
  <title>{{news.title}}</title>
</head>

<body>

  <ul id="nav" class="col-md-1 nav nav-pills nav-stacked">
    <li class="navItem txContainer col-md-12 col-xs-3 ">
      <div class="kb visible-lg visible-md"></div>
      <img src="../public/img/index/logo/logo.png" alt="" class="visible-lg-inline visible-md-inline">
      <div>后台管理</div>
    </li>
    {{each menu}}
    <li class="navItem col-md-12 col-xs-3" data-area="{{$index + 1}}">{{ $value }}</li>
    {{/each}}
  </ul>

  <div id="animeTable" class="col-md-11">
    <div class="tableTitle">
      <a href="javascript:;" class="backLastPage"><span class="return"><img src="../public/img/index/other/back.png"
            alt=""></span></a>
      资讯信息
    </div>
    <div class="editMain">
      <form action="/node/editNew/upload" method="post" enctype="multipart/form-data" class="saveImg saveImg_2"
        target="nm_iframe">
        <input accept="image/png, image/jpeg, image/gif, image/jpg" type="file" class="hide" id="imgInputNew"
          name="image">
        <input type="submit" value="保存上传" class="saveUpload hide">
      </form>

      <div class="main" id="showNewView">
        <div class="row part1" style="padding-bottom:10px;padding-top:10px">
          <div class="form-group newTitle">
            <h3 class="text-center" id="title" style="font-weight: bold">{{news.title}}</h3>
            <div class="text-center" style="margin-top: 15px;">
              <span>{{news.time}}</span>
              <span>作者：{{news.writer}}</span>
              <span id="area">分区：<g style="font-size: 12px;">{{news.area}}</g></span>
              <span>浏览：{{news.readNum + 1}}</span>
              <span class="editBtn">点我编辑</span>
            </div>
          </div>
        </div>

        <div class="row">
          <div class="form-group">
            <div class=" contentView" id="contentNewText">
              {{@news.content}}
            </div>
            <input type="hidden" value="" name="content" id="content">
          </div>
        </div>
      </div>

      <form class="main" id="editNewView" action="/node/editNew" method="post" hidden>
        <div class="row part1" style="padding-bottom:20px">
          <div class="form-group">
            <label for="animeTitle">标题：</label>
            <input type="text" name="title" class="form-control" id="animeTitle" placeholder="标题"
              value="{{news.title}}">
          </div>
          <div class="form-group">
            <label for="animeArea">资讯分区：</label>
            <select class="form-control" name="area" data-value="{{news.area}}" id="areaSelect">
              <option value="日本">日本</option>
              <option value="国产">国产</option>
              <option value="欧美">欧美</option>
            </select>
          </div>
          <div class="form-group hide">
            <label for="animeId">后台ID：</label>
            <input type="text" readonly="readonly" class="form-control" id="new_Id" placeholder="_ID"
              value="{{news._id}}">
          </div>
          <div class="form-group hide">
            <label for="animeId">作者：</label>
            <input type="text" name="writer" class="form-control" id="new_writer" placeholder="作者"
              value="{{news.writer}}">
          </div>
          <div class="form-group hide">
            <label for="animeId">发布时间：</label>
            <input type="text" name="time" class="form-control" id="new_time" placeholder="发布时间" value="{{news.time}}">
          </div>
          <div class="form-group hide">
            <label for="animeId">封面：</label>
            <input type="text" name="imgSrc" class="form-control" id="new_imgSrc" placeholder="封面"
              value="{{news.imgSrc}}">
          </div>
          <div class="form-group hide">
            <label for="animeId">浏览次数</label>
            <input type="number" name="readNum" class="form-control" id="new_readNum" placeholder="浏览次数"
              value="{{news.readNum+1}}">
          </div>
        </div>

        <div class="row">
          <div class="form-group">
            <div class="tableTitle">资讯内容</div>
            <label for="animeContent">
              <div class="btn btn-danger btn-sm" id="newAddImg">添加图片</div>
            </label>
            <div class="form-control" contenteditable="true" id="contentNewText">
              {{@news.content}}
            </div>
            <input class="hide" value="{{news.content}}" name="content" id="content">
          </div>


          <button style="margin-bottom:20px" type="submit" class="btn btn-default editNewSave">保存</button>
        </div>

      </form>

      <!--保存不跳转页面-->
      <iframe id="id_iframe" name="nm_iframe" style="display:none;"></iframe>
    </div>
  </div>





  <script src="../public/js/jquery-1.12.4.min.js"></script>
  <script src="../public/js/vue.min.js"></script>
  <script src="../public/js/vue-resource.min.js"></script>
  <script src="../public/js/layer.js"></script>
  <script src="../public/js/common.js"></script>
  <script>
    // 访问量变化
    $(function () {
      $.ajax({
        type: 'POST', url: '/node/readNum',
        data: { "_id": getUrlParams()._id }
      }).then((res) => { console.log(res) },
        (res) => { console.log(res) });
    })
    
      // 添加图片
      var $focusObj = null;var focusStart = 0;
      var focusLength = 0;
      function appendImg(url){
        var imgObj = document.createElement('img');
        imgObj.className = "img";
        imgObj.src = url;
        if($focusObj==$('#editNewView #contentNewText')|| $focusObj == null){
          $('#editNewView #contentNewText').append(imgObj);
        }
        else if(focusStart>focusLength/2){
          $focusObj.after(imgObj);
        }else{
          $focusObj.before(imgObj);
        }
      }
      function focusThis(){
        $(this).focus();
        var range = window.getSelection();//创建range
        $focusObj = range.anchorNode.parentNode;
        focusLength = range.anchorNode.length;
        focusStart = range.anchorOffset;
      }
      $("#editNewView #contentNewText").on('keyup', focusThis);

      $("#editNewView #contentNewText").on('click',focusThis);
  </script>
  <script src="../public/js/node/index.js"></script>
  
</body>

</html>